﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "ITemporaryDimensionContext.h"
#include "Vector3d.h"
#include "Coordinate3d.h"
#include "Intervald.h"

namespace gcmp
{
    class TemporaryDimensionContext : public ITemporaryDimensionContext
    {
    public:
        explicit TemporaryDimensionContext(const Coordinate3d& coord)
            : m_coord(coord)
            , m_lengthRange(Constants::MIN_NEG_MODEL_SIZE, Constants::MAX_MODEL_SIZE)
            , m_angleRange(-180.0, 180.0)
            , m_isUserCustomInput(false)
            , m_lengthPrecision(2)
            , m_anglePrecision(2)
            , m_radiusPrecision(2)
        {}
        virtual ~TemporaryDimensionContext() {}

    private:
        TemporaryDimensionContext()
            : TemporaryDimensionContext(Coordinate3d())
        {}

    public:
        virtual Intervald GetValidRangeOfLength() const override { return m_lengthRange; }
        virtual bool SetValidRangeOfLength(const Intervald& range) override
        {
            if (range.IsEmpty())
            {
                return false;
            }
            m_lengthRange = range; 
            return true;
        }

        virtual Intervald GetValidRangeOfAngle() const override { return m_angleRange; }
        virtual bool SetValidRangeOfAngle(const Intervald& range) override 
        { 
            if (range.IsEmpty())
            {
                return false;
            }
            m_angleRange = range; 
            return true; 
        }

        virtual void SetUserCustomInput(bool userCustom) override
        {
            m_isUserCustomInput = userCustom;
        }

        Coordinate3d GetCoord() const { return m_coord; }
        bool IsUserCustomInput() const { return m_isUserCustomInput;}

        unsigned int GetLengthPrecision() const
        {
            return m_lengthPrecision;
        }

        virtual void SetLengthPrecision(unsigned int precision) override
        {
            m_lengthPrecision = precision > 12 ? 12 : precision;
        }

        unsigned int GetAnglePrecision() const
        {
            return m_anglePrecision;
        }

        virtual void SetAnglePrecision(unsigned int precision) override
        {
            m_anglePrecision = precision > 12 ? 12 : precision;
        }

        unsigned int GetRadiusPrecision() const
        {
            return m_radiusPrecision;
        }

        virtual void SetRadiusPrecision(unsigned int precision) override
        {
            m_radiusPrecision = precision > 12 ? 12 : precision;
        }

    private:
        Intervald m_lengthRange;
        Intervald m_angleRange;
        bool      m_isUserCustomInput;
        unsigned int m_lengthPrecision;
        unsigned int m_anglePrecision;
        unsigned int m_radiusPrecision;

        Coordinate3d m_coord;
    };


    class LinearTemporaryDimensionContext : public TemporaryDimensionContext
    {
    public:
        LinearTemporaryDimensionContext(
            const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt,
            bool enableLengthDimension, bool enableAngleDimension, const gcmp::Coordinate3d& coord)
            : TemporaryDimensionContext(coord)
            , m_start(startPt), m_end(endPt)
            , m_enableLengthDimension(enableLengthDimension)
            , m_enableAngleDimension(enableAngleDimension)
        {}
        virtual ~LinearTemporaryDimensionContext() {}

    private:
        LinearTemporaryDimensionContext()
            : LinearTemporaryDimensionContext(gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, false, false, gcmp::Coordinate3d())
        {}

    public:
        gcmp::Vector3d GetStartPt() const { return m_start; }
        gcmp::Vector3d GetEndPt() const { return m_end; }
        bool IsLengthDimentionEnabled() const { return m_enableLengthDimension; }
        bool IsAngleDimentionEnabled() const { return m_enableAngleDimension; }

    private:
        gcmp::Vector3d m_start;
        gcmp::Vector3d m_end;
        bool m_enableLengthDimension;
        bool m_enableAngleDimension;
    };

    class RadiusTemporaryDimensionContext : public TemporaryDimensionContext
    {
    public:
        RadiusTemporaryDimensionContext(
            const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt, const gcmp::Vector3d& refPt,
            bool enableArcFillet, const gcmp::Coordinate3d& coord)
            : TemporaryDimensionContext(coord)
            , m_start(startPt), m_end(endPt), m_ref(refPt)
            , m_enableArcFillet(enableArcFillet)
        {}
        virtual ~RadiusTemporaryDimensionContext() {}

    private:
        RadiusTemporaryDimensionContext()
            : RadiusTemporaryDimensionContext(gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, false, gcmp::Coordinate3d())
        {}

    public:
        gcmp::Vector3d GetStartPt() const { return m_start; }
        gcmp::Vector3d GetEndPt() const { return m_end; }
        gcmp::Vector3d GetRefPt() const { return m_ref; }
        bool IsArcFilletEnabled() const { return m_enableArcFillet; }

    private:
        gcmp::Vector3d m_start;
        gcmp::Vector3d m_end;
        gcmp::Vector3d m_ref;
        bool m_enableArcFillet;
    };

    class CentralAngleTemporaryDimensionContext : public TemporaryDimensionContext
    {
    public:
        CentralAngleTemporaryDimensionContext(
            const gcmp::Vector3d& centerPt, const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt, const gcmp::Vector3d& refPt, 
            const gcmp::Coordinate3d& coord)
            : TemporaryDimensionContext(coord)
            , m_center(centerPt), m_start(startPt), m_end(endPt), m_ref(refPt)
        {}
        virtual ~CentralAngleTemporaryDimensionContext() {}

    private:
        CentralAngleTemporaryDimensionContext()
            : CentralAngleTemporaryDimensionContext(gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, gcmp::Coordinate3d())
        {}

    public:
        gcmp::Vector3d GetCenterPt() const { return m_center; }
        gcmp::Vector3d GetStartPt() const { return m_start; }
        gcmp::Vector3d GetEndPt() const { return m_end; }
        gcmp::Vector3d GetRefPt() const { return m_ref; }

    private:
        gcmp::Vector3d m_center;
        gcmp::Vector3d m_start;
        gcmp::Vector3d m_end;
        gcmp::Vector3d m_ref;
    };

    class RotationTemporaryDimensionContext : public TemporaryDimensionContext
    {
    public:
        RotationTemporaryDimensionContext(
            const gcmp::Vector3d& centerPt, const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt, const gcmp::Coordinate3d& coord)
            : TemporaryDimensionContext(coord)
            , m_center(centerPt), m_start(startPt), m_end(endPt)
        {}
        virtual ~RotationTemporaryDimensionContext() {}

    private:
        RotationTemporaryDimensionContext()
            : RotationTemporaryDimensionContext(gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, gcmp::Coordinate3d())
        {}

    public:
        gcmp::Vector3d GetCenterPt() const { return m_center; }
        gcmp::Vector3d GetStartPt() const { return m_start; }
        gcmp::Vector3d GetEndPt() const { return m_end; }
        gcmp::Coordinate3d GetCoord() const { return m_coord; }

    private:
        gcmp::Coordinate3d m_coord;
        gcmp::Vector3d m_center;
        gcmp::Vector3d m_start;
        gcmp::Vector3d m_end;
    };

    class RectangleTemporaryDimensionContext : public TemporaryDimensionContext
    {
    public:
        RectangleTemporaryDimensionContext(
            const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt, const gcmp::Coordinate3d& coord)
            : TemporaryDimensionContext(coord)
            , m_start(startPt), m_end(endPt)
        {}
        virtual ~RectangleTemporaryDimensionContext() {}

    private:
        RectangleTemporaryDimensionContext()
            : RectangleTemporaryDimensionContext(gcmp::Vector3d::Zero, gcmp::Vector3d::Zero, gcmp::Coordinate3d())
        {}

    public:
        gcmp::Vector3d GetStartPt() const { return m_start; }
        gcmp::Vector3d GetEndPt() const { return m_end; }

    private:
        gcmp::Vector3d m_start;
        gcmp::Vector3d m_end;
    };

    class TriangleTemporaryDimensionContext : public TemporaryDimensionContext
    {
    public:
        TriangleTemporaryDimensionContext(
            const gcmp::Vector3d& pt1, const gcmp::Vector3d& pt2, const gcmp::Vector3d& pt3 , const gcmp::Coordinate3d& coord)
            : TemporaryDimensionContext(coord)
            , m_pt1(pt1), m_pt2(pt2),m_pt3(pt3)
        {}
        virtual ~TriangleTemporaryDimensionContext() {}

    private:
        TriangleTemporaryDimensionContext()
            : TriangleTemporaryDimensionContext(gcmp::Vector3d::Zero, gcmp::Vector3d::Zero , gcmp::Vector3d::Zero , gcmp::Coordinate3d())
        {}

    public:
        gcmp::Vector3d GetPt1() const { return m_pt1; }
        gcmp::Vector3d GetPt2() const { return m_pt2; }
        gcmp::Vector3d GetPt3() const { return m_pt3; }

    private:
        gcmp::Vector3d m_pt1;
        gcmp::Vector3d m_pt2;
        gcmp::Vector3d m_pt3;
    };
}


